<template>
  <div class="home">
    <div class="img_text2">江苏</div>

    <div class="login1">
      <el-form
        :model="ruleForm"
        status-icon
        ref="ruleForm"
        label-width="80px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="userName">
          <el-input
            type="password"
            v-model="ruleForm.userName"
            autocomplete="off"
            placeholder="用户名"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            v-model="ruleForm.password"
            autocomplete="off"
            placeholder="密码"
          ></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="captcha">
          <el-row>
            <el-col :span="14">
              <el-input
                type="password"
                v-model="ruleForm.captcha"
                autocomplete="off"
                placeholder="验证码"
              ></el-input>
            </el-col>
            <el-col :span="9" :offset="1">
<!--               :src="captchaPath"   @click="getCaptcha()"-->
              <img
               src="../../assets/img/123.png"
                alt
                style="width: 100%; height: 35px; cursor: pointer"
              />
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item>
          <el-button
            class="logins"
            @click="submit">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import request from "@/api/request";
import { isNil } from "lodash";
import { mapMutations } from "vuex";
// 获取经纬度和地区接口
import { getRegObjectById } from "@/api/system/production";
import { getOrgById } from "@/api/operation/statisticAnalysis";
export default {
  data() {
    var yzm = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入验证码"));
      } else {
        callback();
      }
    };
    var password = (rule, value, callback) => {
      if (value === "" ) {
        callback(new Error("请输入密码"));
      } else {
        callback();
      }
    };
    var userName = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入用户名"));
      } else {
        callback();
      }
    };
    return {
      fullscreenLoading: false, //按钮loading
      uuid: null,
      ruleForm: {
        userName: "*****", //admin
        password: "*****", //user123
        captcha: "*****",
      },
      captchaPath: "",
      rules: {
        userName: [{ validator: userName, trigger: "blur" }],
        password: [{ validator: password, trigger: "blur" }],
        captcha: [{ validator: yzm, trigger: "blur" }],
      },
    };
  },
  created() {
    // 绑定enter事件
    this.enterKeyup();
    localStorage.clear();
    sessionStorage.clear();
  },
  beforeDestroy() {
    // 销毁enter事件
    this.enterKeyupDestroyed();
  },
  mounted() {
    this.getCaptcha();
  },
  methods: {
    ...mapMutations(["stateColseAll", "setPath", "addRoutes"]),
    getPublicKey() {
      return axios({
        url: request.adornUrl(`/authentication/auth/publickey`),
        method: "GET",
      });
    },
    submit() {
      this.$router.push('/evaluation')
    },
    // 获取验证码
    getCaptcha() {
      this.uuid = this.getUUID();
      this.captchaPath = request.captchaPath(this.uuid);
    },
    // getUUID() {
    //   return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
    //     return (
    //       c === "x" ? (Math.random() * 16) | 0 : "r&0x3" | "0x8"
    //     ).toString(16);
    //   });
    // },
    enterKey(event) {
      if (event.keyCode == "13") {
        this.submit();
      }
    },
    enterKeyupDestroyed() {
      document.removeEventListener("keyup", this.enterKey);
    },
    enterKeyup() {
      document.addEventListener("keyup", this.enterKey);
    },

    // 存储regionId
    getOrgByIds(item) {
      getOrgById(item).then((res) => {
        if (res.code === "000000") {
          sessionStorage.setItem("regionId", res.data.regionId);
          this.getRegObjectByIds(res.data.regionId);
        }
      });
    },
    // 获取经纬度和地区昵称
    getRegObjectByIds(item) {
      getRegObjectById(item).then((res) => {

        if (res.code == "000000") {
          sessionStorage.setItem("lng", res.data.lng);
          sessionStorage.setItem("lat", res.data.lat);
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.home {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: hidden;
  min-height: 600px;
  background: url(../../assets/image/bg.png);
  background-size: 100% 100%;
  text-align: center;
  // login 基地自适应
  .logo {
    margin-top: 0.3rem;
    margin-bottom: 0;
    width: 1.65rem;
    height: 0.33rem;
  }
  .img_text {
    font-size: 0.2rem;
    font-weight: 700;
    color: transparent;
    background: linear-gradient(to bottom, #00e6f7, #1198b6);
    -webkit-background-clip: text;
    letter-spacing: 2px;
  }

  .login {
    position: absolute;
    width: 500px;
    height: 300px;
    top: 50%;
    left: 50%;
    margin-top: -150px;
    margin-left: -250px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #74b8c0;
    border-radius: 6px;
    padding: 40px 50px 40px 20px;
    box-sizing: border-box;
    text-align: left;
  }

  // 固定css样式 login
  .logo1 {
    margin-top: 30px;
    margin-bottom: 18px;
  }
  .img_text1 {
    font-size: 35px;
    font-weight: 1000;
    color: transparent;
    background: linear-gradient(to bottom, #00e6f7, #1198b6);
    -webkit-background-clip: text;
    letter-spacing: 2px;
  }
  .login1 {
    position: absolute;
    width: 500px;
    height: 300px;
    margin-top: 110px;
    left: 50%;
    margin-left: -250px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #74b8c0;
    border-radius: 6px;
    padding: 40px 50px 40px 20px;
    box-sizing: border-box;
    text-align: left;
  }
  // 无logo居中
  .img_text2 {
    margin-top: 126px;
    font-size: 35px;
    font-weight: 1000;
    color: transparent;
    background: linear-gradient(to bottom, #00e6f7, #1198b6);
    -webkit-background-clip: text;
    letter-spacing: 2px;
  }
  //登录按钮
  .logins {
    width: 100%;
    height: 40px;
    background: url(../../assets/image/login.png);
    text-align: center;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    border-radius: 4px;
    border: 1px solid #009db0;
  }
  //版本号
  .version {
    position: absolute;
    bottom: 0px;
    left: 0px;
    width: 100%;
    height: 58px;
    font-size: 16px;
    color: #8eaab9;
    text-align: center;
    line-height: 58px;
    background-image: url("../../assets/image/login_foot_bg.png");
  }
}

/deep/ .el-form-item__label {
  color: #e8f1f1;
}
</style>
